package com.kk.nb_mq.listener;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper;
import com.kk.nb_mq.bean.Order;
import com.kk.nb_mq.mapper.OrderMapper;
import com.woniuxy.boot.common.dto.PayDTO;
import org.springframework.amqp.rabbit.annotation.RabbitListener;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

/**
 * @Author: K
 * @Date: 2024/12/16
 */
@Component
public class OrderListener {
    @Autowired
    private OrderMapper orderMapper;

    @RabbitListener(queues = "deadQueue")
    public void listen(PayDTO payDTO) {
        System.out.println(payDTO);
        Order order = new Order();
        order.setId(payDTO.getOrderId());
        order.setUserId(payDTO.getUserId());
        Order order1 = orderMapper.selectOne(new LambdaQueryWrapper<Order>().eq(Order::getUserId, payDTO.getUserId()).eq(Order::getId, order.getId()));
        System.out.println(order1);
        if (order1 != null) {
            if (order1.getPayStatus().equals("a")) {
                orderMapper.update(new LambdaUpdateWrapper<Order>().eq(Order::getId, order.getId()).eq(Order::getUserId, payDTO.getUserId()).set(Order::getPayStatus, "c"));
            }
        }
    }
}

